//
//  MyLocation2.m
//  DriverBus
//
//  Created by MacMini20170218 on 2017/3/28.
//  Copyright © 2017年 JiYang. All rights reserved.
//

#import "MyLocation2.h"

@implementation MyLocation2{
    
}

+ (CLLocationManager*)setLocation:(id)delegate{
    CLLocationManager *locationManager;
    locationManager = [[CLLocationManager alloc]init];
    locationManager.delegate = delegate;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    //每隔多少米定位一次(这里为任何移动)
    locationManager.distanceFilter = kCLDistanceFilterNone;
    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
        [locationManager requestWhenInUseAuthorization];
    }
    
    if(![CLLocationManager locationServicesEnabled]){
        UIAlertView *aler = [[UIAlertView alloc]initWithTitle:@"定位服务未打开" message:@"请开启定位:设置 > 隐私 > 位置 > 定位服务" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [aler show];
    }
    
    if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
        [locationManager requestAlwaysAuthorization]; // 永久授权
        [locationManager requestWhenInUseAuthorization]; //使用中授权
    }
    locationManager.pausesLocationUpdatesAutomatically = NO;
    return locationManager;
}


@end
